package 剑指offer;

import leetcode.day_2020_12_14_12_21.TreeNode;

import java.util.ArrayList;

public class Offer34_JZ24 {
    ArrayList<ArrayList<Integer>> lists = new ArrayList<>();
    ArrayList<Integer> path = new ArrayList<>();
    public ArrayList<ArrayList<Integer>> FindPath(TreeNode root,int target) {
        findP(root, target);
        return lists;
    }

    public void findP(TreeNode root, int target){
        if(root == null) {
            return;
        }
        path.add(root.val);
        target -= root.val;
        if(target==0 && root.left==null && root.right==null){
            lists.add(new ArrayList(path));
        }
        findP(root.left, target);
        findP(root.right, target);
        path.remove(path.size()-1);
    }
}
